package cn.stylefeng.guns.modular.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.IdjTheLicense;
import cn.stylefeng.guns.modular.mapper.IdjTheLicenseMapper;
import cn.stylefeng.guns.modular.service.IIdjTheLicenseService;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * <p>
 * 许可证 服务实现类
 * </p>
 *
 * @author TANGWJ
 * @since 2020-07-30
 */
@Service
public class IdjTheLicenseServiceImpl extends ServiceImpl<IdjTheLicenseMapper, IdjTheLicense> implements IIdjTheLicenseService {

	@Autowired
	private IdjTheLicenseMapper mapper;
	
	@Override
	public LayuiPageInfo getList(Page<IdjTheLicense> page, String keyword, String beginTime, String endTime, String yes,
			String no, Integer isAudit) {
		Page<Map<String, Object>> list = mapper.getList(page, keyword, beginTime, endTime, yes, no, isAudit);
		return LayuiPageFactory.createPageInfo(list);
	}

	@Override
	public ModelAndView edit(Long theLicenseId) {
	    IdjTheLicense license = mapper.selectByTheLicenseId(theLicenseId);
		if(license != null){
			if(ToolUtil.isNotEmpty(license.getReasonType())){
				if(license.getReasonType() == 0){
					license.setReasonTypeName("资料不全");
				}else{
					license.setReasonTypeName("虚假信息");	
				}
			}
			if(ToolUtil.isNotEmpty(license.getIsAudit())){
				if(license.getIsAudit() == 1){
					license.setReasonTypeName("已通过");
				}else{
					license.setReasonTypeName("已拒绝");;	
				}
			}
			List<String> list = new ArrayList<String>();
			if(ToolUtil.isNotEmpty(license.getAuditRejectionImg())){
				String[] split = license.getAuditRejectionImg().split(",");
				for (int i = 0; i < split.length; i++) {
					list.add(split[i]);
				}
				license.setImgList(list);
			}
		}
		ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("license", license);
        return modelAndView;
	}

	@Override
	public int setIsAudit(IdjTheLicense license) {
		return mapper.setIsAudit(license);
	}

}
